/**
 * 格式化文件大小
 * @param size file bytes
 */
function formatFileSize(size) {
  const map = ['', 'K', 'M', 'G', 'T']

  let i = 0
  while (size > 1024) {
    size = size / 1024
    i++
  }

  return `${size.toFixed(2).replace(/\.?0+$/, '')}${map[i]}B`
}

const hasOwnProperty = (obj, property) => Object.prototype.hasOwnProperty.call(obj, property)

module.exports = {
  formatFileSize,
  hasOwnProperty
}
